<template>
  <div>
    <h1>当前的和为:{{$store.state.sum}}</h1>
    <select v-model="n">
      <option :value="1">1</option>
      <option :value="2">2</option>
      <option :value="3">3</option>
    </select>
    <button @click="add">+</button>
    <button @click="unadd">-</button>
    <button @click="addOdd">如果是奇数就加</button>
    <button @click="addWait">等一会儿再加</button>
  </div>
</template>

<script>
export default {
  name: "CountName",
  data() {
    return {
        n:1,
    };
  },
  methods: {
    add() {
      this.$store.dispatch('jia',this.n);
      // this.sum = this.sum+this.n;
    },
    unadd() {
      this.$store.dispatch('jian',this.n);
      
    },
    addOdd() {
      this.$store.dispatch('addodd',this.n);
    },
    addWait() {
      setTimeout(() => {
        this.$store.dispatch('addWait',this.n);
      }, 500);
    },
  },
  mounted(){
    console.log(this);
  }
};
</script>

<style scoped lang="scss" >
button{
    margin-left: 10px;
}
</style>